$(document).ready(function(){
	cw.common.getUserSession(loadT_CHECK_INFO);
})

//载入资产盘点信息
function loadT_CHECK_INFO(){
	var CHECK_NO=$("#CHECK_NO").val();
	if(CHECK_NO==undefined)CHECK_NO="";
	var CHAGE_STATUS=$("#CHAGE_STATUS").val();
	var url = cw.common.path + '/json?action=QUERY_T_CHECK_INFOBY_PAGER_ACTION';
	url += "&CHECK_NO="+CHECK_NO+"&CHAGE_STATUS="+CHAGE_STATUS;
	var xmlname = "T_CHECK_INFO";
	var pagePanel='#T_CHECK_INFO_pager';
	var result='#T_CHECK_INFO_LIST';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	cw.common.changePage(url,pageSize,xmlname,result,fn_queryloadT_CHECK_INFOLLIST,pagePanel,defaultHtml);
}
var fn_queryloadT_CHECK_INFOLLIST = function(obj,result,i){
	var check_status = obj.CHAGE_STATUS;
	if(check_status=='1')check_status='盘点中';else check_status="盘结";
	var str='<li id="bar_'+obj.ID+'">';
	str+='<em style="width: 5%; text-align: center;"><input type="checkbox" id="check_'+obj.ID+'" name="check" value="'+obj.ID+'" /></em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.CHECK_NO+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+cw.common.toChar(obj.CHANGE_BEGIN_DATE,'yyyy-mm-dd')+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+cw.common.toChar(obj.CHANGE_END_DATE,'yyyy-mm-dd')+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+check_status+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.CHENG_BEFULLOF+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.CHENG_LOSE+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.BEFULLOF_LOSE+'</em>';
	str+='<em style="width: 9%; text-align: center;">'+obj.PERSON_NAME+'</em>';
	str+='<em style="width: 15%; text-align: center;">';
	str+='<a href="checkDetail.html?CHECKID='+obj.CHECK_NO+'">盘点</a>&nbsp;&nbsp;&nbsp;';
	str+='<a href="javascript:download(\''+obj.CHECK_NO+'\',\''+obj.CHAGE_STATUS+'\')">下载</a>&nbsp;&nbsp;&nbsp;';
	str+='<a href="javascript:upload(\''+obj.CHECK_NO+'\',\''+obj.CHAGE_STATUS+'\')">上传</a>&nbsp;&nbsp;&nbsp;';
	str+='<a href="javascript:del(\''+obj.ID+'\')">删除</a></em>';
	str+='</li>';
	$(result).append(str);
}

var download =function(id,status){
	
	if(status=='2'){
		alert("该盘点单已盘点，不能再下载盘点资产清单!");
		return ;
	}
	var url = cw.common.path + '/json?action=FILE_UP_DOWNLOAD_ACTION';
	url += "&OPER_TYPE=D&CHECK_NO="+id;
	$.post(url,{},function(data){
		if(data.success){
			location.href = "../report/download.jsp?fileName=pandian.txt&realExportPath="+data.root.T_FILE.rs;
		} else {
			alert(data.errors.errmsg);
		}
	},'json');
}
var upload =function(id,status){
	
	if(status=='2'){
		alert("该盘点单已盘点，不能再上载盘点资产清单!");
		return ;
	}
	window.open ('upload_check_file.html?check_no='+id, 'newwindow', 'height=300, width=500');
}

var del =function(chid){
	$("#check_"+chid).attr("checked",true);
	batchDel();
}

	//批量删除
	function batchDel(){
		if(getCheckedNum('check')==0){
			alert('请选择要删除的盘点单');
			return;
		}
		if(!confirm('确定删除这条盘点单码？')){
			return;
		}
		var barcodeA = getCheckedVal('check').split(',');
		$.post(cw.common.path + '/json',
			{
				action : 'BATCH_DELETE_T_CHECK_INFO_ACTION',
				ID : barcodeA
			}, function(data){
				if (data.success) {
					for(var i=0;i<barcodeA.length;i++)
					{
						$("#bar_"+barcodeA[i]).remove();
					}
					alert('删除盘点单成功');
				} else {
					alert(data.errors.errmsg);
				}
			}, 'json');
	
}